﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SharppiFlowEditor.models;
using System.Drawing;

namespace SharppiFlowEditor.views
{
    class PropertiesView : ScrollableControl
    {

        private Label objTypeLabel, objTextLabel, nodeLocationXLabel, nodeLocationYLabel, connStartNodeLabel, connEndNodeLabel;
        private TextBox objTextTextBox, nodeLocationXTextBox, nodeLocationYTextBox;
        private ListBox objTypeListBox, connStartNodeListBox, connEndNodeListBox;
        private Font usedFont;
        private String[] nodeTypes;
        private String[] connectorTypes;

        private Object _selectedGraphObject;
        public Object SelectedGraphObject
        {
            set { _selectedGraphObject = value; }
        }

        public PropertiesView()
        {
            //this.SuspendLayout();

            //this.BackColor = System.Drawing.Color.White;
            usedFont = new Font(FontFamily.GenericSansSerif, 10.0F);

            this.Dock = DockStyle.Top;

            objTypeLabel = new Label();
            objTypeLabel.Text = "Type";
            objTypeLabel.Font = usedFont;
            objTypeLabel.Location = new Point(2, 110);
            objTypeLabel.Width = 55;
            objTextLabel = new Label();
            objTextLabel.Text = "Text";
            objTextLabel.Font = usedFont;
            objTextLabel.Location = new Point(2, 10);
            objTextLabel.Width = 55;
            nodeLocationXLabel = new Label();
            nodeLocationXLabel.Text = "x-point";
            nodeLocationXLabel.Font = usedFont;
            nodeLocationXLabel.Location = new Point(2, 40);
            nodeLocationXLabel.Width = 55;
            nodeLocationYLabel = new Label();
            nodeLocationYLabel.Text = "y-point";
            nodeLocationYLabel.Font = usedFont;
            nodeLocationYLabel.Location = new Point(2, 70);
            nodeLocationYLabel.Width = 55;

            connStartNodeLabel = new Label();
            connStartNodeLabel.Text = "Start node";
            connStartNodeLabel.Font = usedFont;
            connStartNodeLabel.Location = new Point(2, 40);
            connStartNodeLabel.Width = 55;
            connStartNodeLabel.Height = 35;
            connEndNodeLabel = new Label();
            connEndNodeLabel.Text = "End node";
            connEndNodeLabel.Font = usedFont;
            connEndNodeLabel.Location = new Point(2, 80);
            connEndNodeLabel.Width = 55;
            connEndNodeLabel.Height = 35;

            objTextTextBox = new TextBox();
            objTextTextBox.Font = usedFont;
            objTextTextBox.Location = new Point(60, 10);
            objTextTextBox.Width = 100;
            nodeLocationXTextBox = new TextBox();
            nodeLocationXTextBox.Font = usedFont;
            nodeLocationXTextBox.Location = new Point(60, 40);
            nodeLocationXTextBox.Width = 100;
            nodeLocationYTextBox = new TextBox();
            nodeLocationYTextBox.Font = usedFont;
            nodeLocationYTextBox.Location = new Point(60, 70);
            nodeLocationYTextBox.Width = 100;
            objTypeListBox = new ListBox();
            objTypeListBox.Location = new Point(60, 110);
            objTypeListBox.Size = new Size(100, 60);
            objTypeListBox.SelectionMode = SelectionMode.One;

            connStartNodeListBox = new ListBox();
            connStartNodeListBox.Location = new Point(60, 40);
            connStartNodeListBox.Size = new Size(100, 35);
            connStartNodeListBox.SelectionMode = SelectionMode.One;
            connEndNodeListBox = new ListBox();
            connEndNodeListBox.Location = new Point(60, 80);
            connEndNodeListBox.Size = new Size(100, 35);
            connEndNodeListBox.SelectionMode = SelectionMode.One;

            objTextTextBox.Enabled = false;
            nodeLocationXTextBox.Enabled = false;
            nodeLocationYTextBox.Enabled = false;
            objTypeListBox.Enabled = false;
            

            nodeTypes = new String[] { "Start-node", "Step-node", "Action-node", "End-node" };
            connectorTypes = new String[] { "Connector" };

            //this.AutoScroll = true;
            //this.AutoScrollMinSize = new System.Drawing.Size(200, 500);

            

        }


        // Set SelectedGraphObject-property before calling this.
        public void updatePropertiesView()
        {
            if (_selectedGraphObject is AbstractNode)
            {
                objTextTextBox.Enabled = true;
                objTextTextBox.Text = ((AbstractNode)_selectedGraphObject).Title;
                nodeLocationXTextBox.Enabled = true;
                nodeLocationXTextBox.Text = Convert.ToString(((AbstractNode)_selectedGraphObject).getBoundingRect().X);
                nodeLocationYTextBox.Enabled = true;
                nodeLocationYTextBox.Text = Convert.ToString(((AbstractNode)_selectedGraphObject).getBoundingRect().Y);
                objTypeListBox.Enabled = true;
                objTypeListBox.Items.AddRange(nodeTypes);

                this.Controls.Clear();
                this.Controls.Add(objTextLabel);
                this.Controls.Add(objTextTextBox);
                this.Controls.Add(nodeLocationXLabel);
                this.Controls.Add(nodeLocationXTextBox);
                this.Controls.Add(nodeLocationYLabel);
                this.Controls.Add(nodeLocationYTextBox);
                this.Controls.Add(objTypeLabel);
                this.Controls.Add(objTypeListBox);
            }
            else if (_selectedGraphObject is Connector)
            {
                Connector conn = (Connector)_selectedGraphObject;
                objTextTextBox.Enabled = true;
                objTextTextBox.Text = conn.Text;

                connStartNodeListBox.Items.AddRange(new String[] { conn.Node1.Title, conn.Node2.Title });
                connStartNodeListBox.SelectedIndex = 0;
                connEndNodeListBox.Items.AddRange(new String[] { conn.Node1.Title, conn.Node2.Title });
                connEndNodeListBox.SelectedIndex = 1;

                this.Controls.Clear();
                this.Controls.Add(objTextLabel);
                this.Controls.Add(objTextTextBox);
                this.Controls.Add(connStartNodeLabel);
                this.Controls.Add(connStartNodeListBox);
                this.Controls.Add(connEndNodeLabel);
                this.Controls.Add(connEndNodeListBox);
            }
            
        }

    }
}
